package com.sscw.task.job;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.sscw.task.service.DealJobService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;


@Slf4j
@Component
@AllArgsConstructor
public class SscwDealJob {

    private final DealJobService dealJobService;

    /**
     * 周一领取上周松树
     */
    @XxlJob("pineSettleJobHandler")
    public void pineSettleJobHandler() throws Exception {
        log.info("pineSettleJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.pineSettleJobHandler();
        } catch (Exception e) {
            log.error("pineSettleJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("pineSettleJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 周一记录上周松果榜前20位
     */
    @XxlJob("pineconeRankJobHandler")
    public void pineconeRankJobHandler() throws Exception {
        log.info("pineconeRankJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.pineconeRankJobHandler();
        } catch (Exception e) {
            log.error("pineconeRankJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("pineconeRankJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 处理前一天豪气榜
     */
    @XxlJob("richRankJobHandler")
    public void richRankJobHandler() throws Exception {
        log.info("richRankJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.richRankJobHandler();
        } catch (Exception e) {
            log.error("richRankJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("richRankJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 处理上周推币高手排行榜
     */
    @XxlJob("pushCoinsRankJobHandler")
    public void pushCoinsRankJobHandler() throws Exception {
        log.info("pushCoinsRankJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.pushCoinsRankJobHandler();
        } catch (Exception e) {
            log.error("pushCoinsRankJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("pushCoinsRankJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 处理上周潮玩达人排行榜
     */
    @XxlJob("arcadeMachineRankJobHandler")
    public void arcadeMachineRankJobHandler() throws Exception {
        log.info("arcadeMachineRankJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.arcadeMachineRankJobHandler();
        } catch (Exception e) {
            log.error("arcadeMachineRankJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("arcadeMachineRankJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 处理昨日推币达人挑战排行榜
     */
    @XxlJob("pushCoinsBattleRankJobHandler")
    public void pushCoinsBattleRankJobHandler() throws Exception {
        log.info("pushCoinsBattleRankJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.pushCoinsBattleRankJobHandler();
        } catch (Exception e) {
            log.error("pushCoinsBattleRankJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("pushCoinsBattleRankJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 处理昨日爆爆乐挑战排行榜
     */
    @XxlJob("recreationBattleRankJobHandler")
    public void recreationBattleRankJobHandler() throws Exception {
        log.info("recreationBattleRankJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.recreationBattleRankJobHandler();
        } catch (Exception e) {
            log.error("recreationBattleRankJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("recreationBattleRankJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 处理昨日街机挑战排行榜
     */
    @XxlJob("arcadeMachineBattleRankJobHandler")
    public void arcadeMachineBattleRankJobHandler() throws Exception {
        log.info("arcadeMachineBattleRankJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.arcadeMachineBattleRankJobHandler();
        } catch (Exception e) {
            log.error("arcadeMachineBattleRankJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("arcadeMachineBattleRankJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 结算街机娱乐
     */
    @XxlJob("settleArcadeMachineJobHandler")
    public void settleArcadeMachineJobHandler() throws Exception {
        log.info("settleArcadeMachineJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.settleArcadeMachineJobHandler();
        } catch (Exception e) {
            log.error("settleArcadeMachineJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("settleArcadeMachineJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 结算推币机包机
     */
    @XxlJob("settlePushCoinsOccupyJobHandler")
    public void settlePushCoinsOccupyJobHandler() throws Exception {
        log.info("settlePushCoinsOccupyJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.settlePushCoinsOccupyJobHandler();
        } catch (Exception e) {
            log.error("settlePushCoinsOccupyJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("settlePushCoinsOccupyJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 每天发放周卡月卡
     */
    @XxlJob("grantCardJobHandler")
    public void grantCardJobHandler() throws Exception {
        log.info("grantCardJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.grantCardJobHandler();
        } catch (Exception e) {
            log.error("grantCardJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("grantCardJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 每周一发放权益
     */
    @XxlJob("grantEquityJobHandler")
    public void grantEquityJobHandler() throws Exception {
        log.info("grantEquityJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.grantEquityJobHandler();
        } catch (Exception e) {
            log.error("grantEquityJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("grantEquityJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 每天清理两天前mqtt消息
     */
    @XxlJob("deleteMqttMessageJobHandler")
    public void deleteMqttMessageJobHandler() throws Exception {
        log.info("deleteMqttMessageJobHandler开始执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.deleteMqttMessageJobHandler();
        } catch (Exception e) {
            log.error("deleteMqttMessageJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("deleteMqttMessageJobHandler结束执行：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }

    /**
     * 彩票排行榜统计-日榜
     */
    @XxlJob("dealPinecutDailyRankJobHandler")
    public void dealPinecutDailyRankJobHandler() throws Exception {
        log.info("dealPinecutDailyRankJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.dealPinecutRankDailyJobHandler(false);
        } catch (Exception e) {
            log.error("dealPinecutDailyRankJobHandler执行异常：{}", e);
            throw new Exception(e);
        }
        log.info("dealPinecutDailyRankJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }
    /**
     * 彩票排行榜统计和发放奖励-日榜
     */
    @XxlJob("dealPinecutDailyRankAndPutPrizeJobHandler")
    public void dealPinecutDailyRankAndPutPrizeJobHandler() throws Exception {
        log.info("dealPinecutDailyRankAndPutPrizeJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.dealPinecutRankDailyJobHandler(true);
        } catch (Exception e) {
            log.error("dealPinecutDailyRankAndPutPrizeJobHandler：{}", e);
            throw new Exception(e);
        }
        log.info("dealPinecutDailyRankAndPutPrizeJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }


    /**
     * 彩票排行榜统计-周榜
     */
    @XxlJob("dealPinecutWeekRankJobHandler")
    public void dealPinecutWeekRankJobHandler() throws Exception {
        log.info("dealPinecutWeekRankJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.dealPinecutRankWeekJobHandler(false);
        } catch (Exception e) {
            log.error("dealPinecutWeekRankJobHandler：{}", e);
            throw new Exception(e);
        }
        log.info("dealPinecutWeekRankJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }
    /**
     * 彩票排行榜统计和发放奖励-周榜
     */
    @XxlJob("dealPinecutWeekRankAndPutPrizeJobHandler")
    public void dealPinecutWeekRankAndPutPrizeJobHandler() throws Exception {
        log.info("dealPinecutWeekRankAndPutPrizeJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.dealPinecutRankWeekJobHandler(true);
        } catch (Exception e) {
            log.error("dealPinecutWeekRankAndPutPrizeJobHandler：{}", e);
            throw new Exception(e);
        }
        log.info("dealPinecutWeekRankAndPutPrizeJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }


    /**
     * 道具月度赠送处理
     */
    @XxlJob("doCardGiveJobHandler")
    public void doCardGiveJobHandler() throws Exception {
        log.info("doCardGiveJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
        try {
            dealJobService.doCardGiveJobHandler();
        } catch (Exception e) {
            log.error("doCardGiveJobHandler：{}", e);
            throw new Exception(e);
        }
        log.info("doCardGiveJobHandler：{}", LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
    }
}
